local EquipDataHelper = {}

function EquipDataHelper.getEquipmentEffect(unit, result)
    local config = unit:getConfig()
    if config.effect_id > 0 then
        table.insert(result, config.effect_id)
    end
end

function EquipDataHelper.getEquipmentUpCost(unit, addLevel)
    local TypeHelper = require("utils.TypeHelper")
    local DataConst = require("const.DataConst")
    local upLevel = addLevel or 1
    local config = unit:getConfig()
    local level = unit:getLevel()
    local lvId = config.lv_id
    local toLevel = level + upLevel
    toLevel = toLevel > config.lv_max and config.lv_max or toLevel
    local costMoney = 0
    local costItem = {}
    costItem.type = 0
    costItem.value = 0
    costItem.size = 0
    for i = level + 1, toLevel do
        local cfg = require("config.equipment_lvup").get(lvId, i)
        costMoney = costMoney + cfg.cost

        costItem.type = cfg.cost_type
        costItem.value = cfg.cost_value
        costItem.size = costItem.size + cfg.cost_size
    end
    return costMoney, costItem
end

function EquipDataHelper.getEquipmentAttr(unit)
    local config = unit:getConfig()
    local lvId = config.lv_id
    local level = unit:getLevel()
    local mainAttr = {}
    mainAttr.id = config.mainAttrId
    mainAttr.value = 0
    local subAttr = {}
    subAttr.id = config.subAttrId
    subAttr.value = 0
    for i = 1, level do
        local cfg = require("config.equipment_lvup").get(lvId, i)
        mainAttr.value = mainAttr.value + cfg.mainAdd
        subAttr.value = subAttr.value + cfg.subAdd
    end
    return mainAttr, subAttr
end

return EquipDataHelper
